#ifndef RootFinder_h_
#define RootFinder_h_

#include    <Function.h>

// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
class RootFinder
{
public:
    /** Finds roots of a function on the given interval.
     */
    static void         FindRoots
                            (
                            Function&       func,
                            const Real&     from,
                            const Real&     to,
                            RealList&       roots
                            );

    /** Finds a SINGLE root of a function on the given interval.
     *  Returns an error if root cannot be found.
     */
    static Status       FindRoot
                            (
                            Function&       func,
                            const Real&     from,
                            const Real&     to,
                            Real&           root
                            );

    /** Returns -1, 0, or 1 depending on the sign of the value.
     */
    static Int          Sign(const Real& x);

    static const UInt   MAX_ITERATIONS;

private:
    /** Narrows down the given interval to include one root.
     *
     *  This helps prevent awkward boundary conditions around singularities.
     */
    static Status       AdjustInterval
                            (
                            Function&       func,
                            Real&           from,
                            Real&           to
                            );
};

#endif

// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// eof
